<template>
  <div class="app-container">
    <el-button size="mini" type="text" @click="to">日志</el-button>
    <eHeader :query="query" />
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;">
      <!-- <el-table-column prop="id" label="id"/>-->
      <el-table-column prop="orderId" label="工单编号" />
      <el-table-column prop="orderStatus" label="工单状态">
        <template slot-scope="scope">
          <div v-for="item in statusOptions" :key="item.id">
            <el-tag v-show="scope.row.orderStatus.toString() === item.value">{{ item.label }}</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="operator" label="操作人" />
      <el-table-column prop="operator" label="操作时间" />
      <el-table-column prop="content" label="日志内容" />
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"
    />
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import { get } from '@/api/dictDetail'
import { del } from '@/api/tWorkOrderLog'
import eHeader from './module/header'
export default {
  name: 'LogOrder',
  components: { eHeader },
  data() {
    return {
      delLoading: false,
      supThis: this,
      statusOptions: []
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
      this.getDict('order_status')
    })
  },
  methods: {
    checkPermission,
    beforeInit() {
      this.url = 'api/tWorkOrderLog'
      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size, sort: sort }
      return true
    },
    async getDict(name) {
      return new Promise((resolve, reject) => {
        get(name).then(res => {
          if (name === 'order_status') { this.statusOptions = res.content } else if (name === 'fault_type') { this.faultTypes = res.content } else { this.serviceLevels = res.content }
          resolve(res)
        }).catch(err => {
          reject(err)
        })
      })
    },
    subDelete(id) {
      this.delLoading = true
      del(id).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err)
      })
    }
  }
}
</script>

<style scoped>

</style>
